<?php

if (! function_exists('show_array_dropdown'))
{
	function show_array_dropdown($array, $key, $value, $default = '', $name, $id = '', $attributes = '')
    {		
		if ($attributes != '')
		{
			$attributes = _parse_attributes($attributes);
		}
		
		if (! $id) $id = $name;
        
        $menu  = '<select name="' . $name . '" id="' . $id . '" class="textselect"' . $attributes . '>';
        $menu .= '<option value=""></option>';
        
		// check if an array is passed
		// still display select if not
		if (is_array($array))
		{
			foreach ($array as $v)
			{
				if (is_array($default))
				{
					$selected = (in_array($v[$key], $default)) ? ' selected="selected"' : '';
				}
				else
				{
					$selected = ($default == $v[$key]) ? ' selected="selected"' : '';
				}
				
				$menu .= '<option value="' . $v[$key] . '"' . $selected . '>' . $v[$value] . '</option>';
			}
		}
        
        $menu .= '</select>';
        
        return $menu;
    }
}

// ------------------------------------------------------------------------

if (! function_exists('json_response'))
{
	function json_response($success, $action = '', $text = '', $text2 = '')
	{
		$response['success'] = $success;
		
		if ($action)
		{
			$response['action'] = $action;
			
			if ($text)
			{
				$response['text'] = $text;
			}
			
			if ($text2)
			{
				$response['text2'] = $text2;
			}
		}
		
		echo json_encode($response);
		return TRUE;
	}
}

// --------------------------------------------------------------------

if (! function_exists('script_tag'))
{
	function script_tag($url = '')
	{
		$src = site_url($url);
		return '<script src="' . $src .'"></script>' . "\n";
	}
}